package my.test.csdn.weixin_43767015.basic.ch12.transaction.declarative.annotation.eachcall.service.transform;

import javax.annotation.Resource;

import org.springframework.aop.framework.AopContext;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
public class EachCallTransform2 {
	
    /**
     * jdbc模版，用于操作数据库
     */
    @Resource
    private JdbcTemplate jdbcTemplate;
	
    public void m1() {
       //获取当前暴露的AOP代理对象
       EachCallTransform2 o = (EachCallTransform2) AopContext.currentProxy();
       //通过代理对象调用方法
       o.m2();
    }
    
    @Transactional
    public void m2() {
        String sql = "insert into tx_study (name,age) values (?,?)";
        jdbcTemplate.update(sql, "EachCall", 30);
        //抛出一个RuntimeException
        throw new RuntimeException();
    }

}
